package com.yang.action;

import com.yang.entity.Product;
import com.yang.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;

@WebServlet("/updateProduct")
public class ProductUpdateAction extends HttpServlet {
    ProductService productService = new ProductService();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Product product = new Product();
        String id = req.getParameter("id");
        product.setId(Integer.parseInt(id));
        String name = req.getParameter("name");
        product.setName(name);
        String url = req.getParameter("url");
        product.setUrl(url);
        String price = req.getParameter("price");
        String stock = req.getParameter("stock");
        product.setStock(Integer.parseInt(stock));
        String detail = req.getParameter("detail");
        product.setDetail(detail);
        String categoryId = req.getParameter("categoryId");
        product.setCategoryId(Integer.parseInt(categoryId));
        int num = productService.updateProductById(product);
        resp.setContentType("text/text;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print(num);
        out.flush();
        out.close();
    }
}

